package com.object.module.sys.controller;

import com.common.rabitmq.RabbitmqName;
import com.common.rabitmq.RabbitmqTime;
import com.object.configuration.utils.Q;
import com.object.module.sys.service.TTestSerivce;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/test")
public class TTetsController {
 @Autowired
 private RabbitTemplate rabbitTemplate;

 @Autowired
 private TTestSerivce  tTestSerivce;


 @GetMapping("test")
 public void contextLoads() {
  rabbitTemplate.convertAndSend("delay_change", RabbitmqName.RAPID_ORDER_ROUTING_KEY,"123"
          ,message->{
   //设置我们的信息传递方式
    message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
    //设置我们延迟的时长 10秒 才把信息发送过去
      message.getMessageProperties().setDelay(RabbitmqTime.seconds(15));
      return message;
  });
  System.out.println("当前发送时间："+new SimpleDateFormat("HH:mm:ss").format(new Date()));
 }

  @RequestMapping("/save")
  public Q saveId(@RequestBody Integer id){
   return tTestSerivce.saveId(id);
  }


/* @Value("${name}")
 private String namel;

 @GetMapping("/testIndex")
 public String info(){
  return namel;
 }*/
}
